package com.cw.paging3

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import kotlinx.coroutines.flow.Flow

class MainViewModel: ViewModel() {
    // .flow表示结果由LiveData转为Flow
    // cachedIn表示将结果缓存到viewModelScope，在ViewModel的onClear之前将一直存在
//    val listDataFlow = Pager(PagingConfig(pageSize = 6)) {
//        PostDataSource(apiService)
//    }.flow
//        .cachedIn(viewModelScope)

    fun getPagingData(): Flow<PagingData<Data>> {
        return Repository.getPagingData().cachedIn(viewModelScope)
    }
}
